<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>path.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_graphics_path.js.html">path.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2007 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>
<a name="line16"></a>/**
<a name="line17"></a> * @fileoverview Represents a path used with a Graphics implementation.
<a name="line18"></a> * @author arv@google.com (Erik Arvidsson)
<a name="line19"></a> * @author glenning@google.com (Anthony Glenning)
<a name="line20"></a> */
<a name="line21"></a>
<a name="line22"></a>goog.provide(&#39;goog.graphics.Path&#39;);
<a name="line23"></a>goog.provide(&#39;goog.graphics.Path.Segment&#39;);
<a name="line24"></a>
<a name="line25"></a>goog.require(&#39;goog.array&#39;);
<a name="line26"></a>goog.require(&#39;goog.math&#39;);
<a name="line27"></a>
<a name="line28"></a>
<a name="line29"></a>
<a name="line30"></a>/**
<a name="line31"></a> * Creates a path object. A path is a sequence of segments and may be open or
<a name="line32"></a> * closed. Path uses the EVEN-ODD fill rule for determining the interior of the
<a name="line33"></a> * path. A path must start with a moveTo command.
<a name="line34"></a> *
<a name="line35"></a> * A &quot;simple&quot; path does not contain any arcs and may be transformed using
<a name="line36"></a> * the {@code transform} method.
<a name="line37"></a> *
<a name="line38"></a> * @constructor
<a name="line39"></a> */
<a name="line40"></a>goog.graphics.Path = function() {
<a name="line41"></a>  /**
<a name="line42"></a>   * The segment types that constitute this path.
<a name="line43"></a>   * @type {!Array.&lt;number&gt;}
<a name="line44"></a>   * @private
<a name="line45"></a>   */
<a name="line46"></a>  this.segments_ = [];
<a name="line47"></a>
<a name="line48"></a>  /**
<a name="line49"></a>   * The number of repeated segments of the current type.
<a name="line50"></a>   * @type {!Array.&lt;number&gt;}
<a name="line51"></a>   * @private
<a name="line52"></a>   */
<a name="line53"></a>  this.count_ = [];
<a name="line54"></a>
<a name="line55"></a>  /**
<a name="line56"></a>   * The arguments corresponding to each of the segments.
<a name="line57"></a>   * @type {!Array.&lt;number&gt;}
<a name="line58"></a>   * @private
<a name="line59"></a>   */
<a name="line60"></a>  this.arguments_ = [];
<a name="line61"></a>};
<a name="line62"></a>
<a name="line63"></a>
<a name="line64"></a>/**
<a name="line65"></a> * The coordinates of the point which closes the path (the point of the
<a name="line66"></a> * last moveTo command).
<a name="line67"></a> * @type {Array.&lt;number&gt;?}
<a name="line68"></a> * @private
<a name="line69"></a> */
<a name="line70"></a>goog.graphics.Path.prototype.closePoint_ = null;
<a name="line71"></a>
<a name="line72"></a>
<a name="line73"></a>/**
<a name="line74"></a> * The coordinates most recently added to the end of the path.
<a name="line75"></a> * @type {Array.&lt;number&gt;?}
<a name="line76"></a> * @private
<a name="line77"></a> */
<a name="line78"></a>goog.graphics.Path.prototype.currentPoint_ = null;
<a name="line79"></a>
<a name="line80"></a>
<a name="line81"></a>/**
<a name="line82"></a> * Flag for whether this is a simple path (contains no arc segments).
<a name="line83"></a> * @type {boolean}
<a name="line84"></a> * @private
<a name="line85"></a> */
<a name="line86"></a>goog.graphics.Path.prototype.simple_ = true;
<a name="line87"></a>
<a name="line88"></a>
<a name="line89"></a>/**
<a name="line90"></a> * Path segment types.
<a name="line91"></a> * @enum {number}
<a name="line92"></a> */
<a name="line93"></a>goog.graphics.Path.Segment = {
<a name="line94"></a>  MOVETO: 0,
<a name="line95"></a>  LINETO: 1,
<a name="line96"></a>  CURVETO: 2,
<a name="line97"></a>  ARCTO: 3,
<a name="line98"></a>  CLOSE: 4
<a name="line99"></a>};
<a name="line100"></a>
<a name="line101"></a>
<a name="line102"></a>/**
<a name="line103"></a> * The number of points for each segment type.
<a name="line104"></a> * @type {!Array.&lt;number&gt;}
<a name="line105"></a> * @private
<a name="line106"></a> */
<a name="line107"></a>goog.graphics.Path.segmentArgCounts_ = (function() {
<a name="line108"></a>  var counts = [];
<a name="line109"></a>  counts[goog.graphics.Path.Segment.MOVETO] = 2;
<a name="line110"></a>  counts[goog.graphics.Path.Segment.LINETO] = 2;
<a name="line111"></a>  counts[goog.graphics.Path.Segment.CURVETO] = 6;
<a name="line112"></a>  counts[goog.graphics.Path.Segment.ARCTO] = 6;
<a name="line113"></a>  counts[goog.graphics.Path.Segment.CLOSE] = 0;
<a name="line114"></a>  return counts;
<a name="line115"></a>})();
<a name="line116"></a>
<a name="line117"></a>
<a name="line118"></a>/**
<a name="line119"></a> * Returns the number of points for a segment type.
<a name="line120"></a> *
<a name="line121"></a> * @param {number} segment The segment type.
<a name="line122"></a> * @return {number} The number of points.
<a name="line123"></a> */
<a name="line124"></a>goog.graphics.Path.getSegmentCount = function(segment) {
<a name="line125"></a>  return goog.graphics.Path.segmentArgCounts_[segment];
<a name="line126"></a>};
<a name="line127"></a>
<a name="line128"></a>
<a name="line129"></a>/**
<a name="line130"></a> * Appends another path to the end of this path.
<a name="line131"></a> *
<a name="line132"></a> * @param {!goog.graphics.Path} path The path to append.
<a name="line133"></a> * @return {!goog.graphics.Path} This path.
<a name="line134"></a> */
<a name="line135"></a>goog.graphics.Path.prototype.appendPath = function(path) {
<a name="line136"></a>  if (path.currentPoint_) {
<a name="line137"></a>    Array.prototype.push.apply(this.segments_, path.segments_);
<a name="line138"></a>    Array.prototype.push.apply(this.count_, path.count_);
<a name="line139"></a>    Array.prototype.push.apply(this.arguments_, path.arguments_);
<a name="line140"></a>    this.currentPoint_ = path.currentPoint_.concat();
<a name="line141"></a>    this.closePoint_ = path.closePoint_.concat();
<a name="line142"></a>    this.simple_ = this.simple_ &amp;&amp; path.simple_;
<a name="line143"></a>  }
<a name="line144"></a>  return this;
<a name="line145"></a>};
<a name="line146"></a>
<a name="line147"></a>
<a name="line148"></a>/**
<a name="line149"></a> * Clears the path.
<a name="line150"></a> *
<a name="line151"></a> * @return {!goog.graphics.Path} The path itself.
<a name="line152"></a> */
<a name="line153"></a>goog.graphics.Path.prototype.clear = function() {
<a name="line154"></a>  this.segments_.length = 0;
<a name="line155"></a>  this.count_.length = 0;
<a name="line156"></a>  this.arguments_.length = 0;
<a name="line157"></a>  delete this.closePoint_;
<a name="line158"></a>  delete this.currentPoint_;
<a name="line159"></a>  delete this.simple_;
<a name="line160"></a>  return this;
<a name="line161"></a>};
<a name="line162"></a>
<a name="line163"></a>
<a name="line164"></a>/**
<a name="line165"></a> * Adds a point to the path by moving to the specified point. Repeated moveTo
<a name="line166"></a> * commands are collapsed into a single moveTo.
<a name="line167"></a> *
<a name="line168"></a> * @param {number} x X coordinate of destination point.
<a name="line169"></a> * @param {number} y Y coordinate of destination point.
<a name="line170"></a> * @return {!goog.graphics.Path} The path itself.
<a name="line171"></a> */
<a name="line172"></a>goog.graphics.Path.prototype.moveTo = function(x, y) {
<a name="line173"></a>  if (goog.array.peek(this.segments_) == goog.graphics.Path.Segment.MOVETO) {
<a name="line174"></a>    this.arguments_.length -= 2;
<a name="line175"></a>  } else {
<a name="line176"></a>    this.segments_.push(goog.graphics.Path.Segment.MOVETO);
<a name="line177"></a>    this.count_.push(1);
<a name="line178"></a>  }
<a name="line179"></a>  this.arguments_.push(x, y);
<a name="line180"></a>  this.currentPoint_ = this.closePoint_ = [x, y];
<a name="line181"></a>  return this;
<a name="line182"></a>};
<a name="line183"></a>
<a name="line184"></a>
<a name="line185"></a>/**
<a name="line186"></a> * Adds points to the path by drawing a straight line to each point.
<a name="line187"></a> *
<a name="line188"></a> * @param {...number} var_args The coordinates of each destination point as x, y
<a name="line189"></a> *     value pairs.
<a name="line190"></a> * @return {!goog.graphics.Path} The path itself.
<a name="line191"></a> */
<a name="line192"></a>goog.graphics.Path.prototype.lineTo = function(var_args) {
<a name="line193"></a>  var lastSegment = goog.array.peek(this.segments_);
<a name="line194"></a>  if (lastSegment == null) {
<a name="line195"></a>    throw Error(&#39;Path cannot start with lineTo&#39;);
<a name="line196"></a>  }
<a name="line197"></a>  if (lastSegment != goog.graphics.Path.Segment.LINETO) {
<a name="line198"></a>    this.segments_.push(goog.graphics.Path.Segment.LINETO);
<a name="line199"></a>    this.count_.push(0);
<a name="line200"></a>  }
<a name="line201"></a>  for (var i = 0; i &lt; arguments.length; i += 2) {
<a name="line202"></a>    var x = arguments[i];
<a name="line203"></a>    var y = arguments[i + 1];
<a name="line204"></a>    this.arguments_.push(x, y);
<a name="line205"></a>  }
<a name="line206"></a>  this.count_[this.count_.length - 1] += i / 2;
<a name="line207"></a>  this.currentPoint_ = [x, y];
<a name="line208"></a>  return this;
<a name="line209"></a>};
<a name="line210"></a>
<a name="line211"></a>
<a name="line212"></a>/**
<a name="line213"></a> * Adds points to the path by drawing cubic Bezier curves. Each curve is
<a name="line214"></a> * specified using 3 points (6 coordinates) - two control points and the end
<a name="line215"></a> * point of the curve.
<a name="line216"></a> *
<a name="line217"></a> * @param {...number} var_args The coordinates specifiying each curve in sets of
<a name="line218"></a> *     6 points: {@code [x1, y1]} the first control point, {@code [x2, y2]} the
<a name="line219"></a> *     second control point and {@code [x, y]} the end point.
<a name="line220"></a> * @return {!goog.graphics.Path} The path itself.
<a name="line221"></a> */
<a name="line222"></a>goog.graphics.Path.prototype.curveTo = function(var_args) {
<a name="line223"></a>  var lastSegment = goog.array.peek(this.segments_);
<a name="line224"></a>  if (lastSegment == null) {
<a name="line225"></a>    throw Error(&#39;Path cannot start with curve&#39;);
<a name="line226"></a>  }
<a name="line227"></a>  if (lastSegment != goog.graphics.Path.Segment.CURVETO) {
<a name="line228"></a>    this.segments_.push(goog.graphics.Path.Segment.CURVETO);
<a name="line229"></a>    this.count_.push(0);
<a name="line230"></a>  }
<a name="line231"></a>  for (var i = 0; i &lt; arguments.length; i += 6) {
<a name="line232"></a>    var x = arguments[i + 4];
<a name="line233"></a>    var y = arguments[i + 5];
<a name="line234"></a>    this.arguments_.push(arguments[i], arguments[i + 1],
<a name="line235"></a>        arguments[i + 2], arguments[i + 3], x, y);
<a name="line236"></a>  }
<a name="line237"></a>  this.count_[this.count_.length - 1] += i / 6;
<a name="line238"></a>  this.currentPoint_ = [x, y];
<a name="line239"></a>  return this;
<a name="line240"></a>};
<a name="line241"></a>
<a name="line242"></a>
<a name="line243"></a>/**
<a name="line244"></a> * Adds a path command to close the path by connecting the
<a name="line245"></a> * last point to the first point.
<a name="line246"></a> *
<a name="line247"></a> * @return {!goog.graphics.Path} The path itself.
<a name="line248"></a> */
<a name="line249"></a>goog.graphics.Path.prototype.close = function() {
<a name="line250"></a>  var lastSegment = goog.array.peek(this.segments_);
<a name="line251"></a>  if (lastSegment == null) {
<a name="line252"></a>    throw Error(&#39;Path cannot start with close&#39;);
<a name="line253"></a>  }
<a name="line254"></a>  if (lastSegment != goog.graphics.Path.Segment.CLOSE) {
<a name="line255"></a>    this.segments_.push(goog.graphics.Path.Segment.CLOSE);
<a name="line256"></a>    this.count_.push(1);
<a name="line257"></a>    this.currentPoint_ = this.closePoint_;
<a name="line258"></a>  }
<a name="line259"></a>  return this;
<a name="line260"></a>};
<a name="line261"></a>
<a name="line262"></a>
<a name="line263"></a>/**
<a name="line264"></a> * Adds a path command to draw an arc centered at the point {@code (cx, cy)}
<a name="line265"></a> * with radius {@code rx} along the x-axis and {@code ry} along the y-axis from
<a name="line266"></a> * {@code startAngle} through {@code extent} degrees. Positive rotation is in
<a name="line267"></a> * the direction from positive x-axis to positive y-axis.
<a name="line268"></a> *
<a name="line269"></a> * @param {number} cx X coordinate of center of ellipse.
<a name="line270"></a> * @param {number} cy Y coordinate of center of ellipse.
<a name="line271"></a> * @param {number} rx Radius of ellipse on x axis.
<a name="line272"></a> * @param {number} ry Radius of ellipse on y axis.
<a name="line273"></a> * @param {number} fromAngle Starting angle measured in degrees from the
<a name="line274"></a> *     positive x-axis.
<a name="line275"></a> * @param {number} extent The span of the arc in degrees.
<a name="line276"></a> * @param {boolean} connect If true, the starting point of the arc is connected
<a name="line277"></a> *     to the current point.
<a name="line278"></a> * @return {!goog.graphics.Path} The path itself.
<a name="line279"></a> * @deprecated Use {@code arcTo} or {@code arcToAsCurves} instead.
<a name="line280"></a> */
<a name="line281"></a>goog.graphics.Path.prototype.arc = function(cx, cy, rx, ry,
<a name="line282"></a>    fromAngle, extent, connect) {
<a name="line283"></a>  var startX = cx + goog.math.angleDx(fromAngle, rx);
<a name="line284"></a>  var startY = cy + goog.math.angleDy(fromAngle, ry);
<a name="line285"></a>  if (connect) {
<a name="line286"></a>    if (!this.currentPoint_ || startX != this.currentPoint_[0] ||
<a name="line287"></a>        startY != this.currentPoint_[1]) {
<a name="line288"></a>      this.lineTo(startX, startY);
<a name="line289"></a>    }
<a name="line290"></a>  } else {
<a name="line291"></a>    this.moveTo(startX, startY);
<a name="line292"></a>  }
<a name="line293"></a>  return this.arcTo(rx, ry, fromAngle, extent);
<a name="line294"></a>};
<a name="line295"></a>
<a name="line296"></a>
<a name="line297"></a>/**
<a name="line298"></a> * Adds a path command to draw an arc starting at the path&#39;s current point,
<a name="line299"></a> * with radius {@code rx} along the x-axis and {@code ry} along the y-axis from
<a name="line300"></a> * {@code startAngle} through {@code extent} degrees. Positive rotation is in
<a name="line301"></a> * the direction from positive x-axis to positive y-axis.
<a name="line302"></a> *
<a name="line303"></a> * This method makes the path non-simple.
<a name="line304"></a> *
<a name="line305"></a> * @param {number} rx Radius of ellipse on x axis.
<a name="line306"></a> * @param {number} ry Radius of ellipse on y axis.
<a name="line307"></a> * @param {number} fromAngle Starting angle measured in degrees from the
<a name="line308"></a> *     positive x-axis.
<a name="line309"></a> * @param {number} extent The span of the arc in degrees.
<a name="line310"></a> * @return {!goog.graphics.Path} The path itself.
<a name="line311"></a> */
<a name="line312"></a>goog.graphics.Path.prototype.arcTo = function(rx, ry, fromAngle, extent) {
<a name="line313"></a>  var cx = this.currentPoint_[0] - goog.math.angleDx(fromAngle, rx);
<a name="line314"></a>  var cy = this.currentPoint_[1] - goog.math.angleDy(fromAngle, ry);
<a name="line315"></a>  var ex = cx + goog.math.angleDx(fromAngle + extent, rx);
<a name="line316"></a>  var ey = cy + goog.math.angleDy(fromAngle + extent, ry);
<a name="line317"></a>  this.segments_.push(goog.graphics.Path.Segment.ARCTO);
<a name="line318"></a>  this.count_.push(1);
<a name="line319"></a>  this.arguments_.push(rx, ry, fromAngle, extent, ex, ey);
<a name="line320"></a>  this.simple_ = false;
<a name="line321"></a>  this.currentPoint_ = [ex, ey];
<a name="line322"></a>  return this;
<a name="line323"></a>};
<a name="line324"></a>
<a name="line325"></a>
<a name="line326"></a>/**
<a name="line327"></a> * Same as {@code arcTo}, but approximates the arc using bezier curves.
<a name="line328"></a>.* As a result, this method does not affect the simplified status of this path.
<a name="line329"></a> * The algorithm is adapted from {@code java.awt.geom.ArcIterator}.
<a name="line330"></a> *
<a name="line331"></a> * @param {number} rx Radius of ellipse on x axis.
<a name="line332"></a> * @param {number} ry Radius of ellipse on y axis.
<a name="line333"></a> * @param {number} fromAngle Starting angle measured in degrees from the
<a name="line334"></a> *     positive x-axis.
<a name="line335"></a> * @param {number} extent The span of the arc in degrees.
<a name="line336"></a> * @return {!goog.graphics.Path} The path itself.
<a name="line337"></a> */
<a name="line338"></a>goog.graphics.Path.prototype.arcToAsCurves = function(
<a name="line339"></a>    rx, ry, fromAngle, extent) {
<a name="line340"></a>  var cx = this.currentPoint_[0] - goog.math.angleDx(fromAngle, rx);
<a name="line341"></a>  var cy = this.currentPoint_[1] - goog.math.angleDy(fromAngle, ry);
<a name="line342"></a>  var extentRad = goog.math.toRadians(extent);
<a name="line343"></a>  var arcSegs = Math.ceil(Math.abs(extentRad) / Math.PI * 2);
<a name="line344"></a>  var inc = extentRad / arcSegs;
<a name="line345"></a>  var angle = goog.math.toRadians(fromAngle);
<a name="line346"></a>  for (var j = 0; j &lt; arcSegs; j++) {
<a name="line347"></a>    var relX = Math.cos(angle);
<a name="line348"></a>    var relY = Math.sin(angle);
<a name="line349"></a>    var z = 4 / 3 * Math.sin(inc / 2) / (1 + Math.cos(inc / 2));
<a name="line350"></a>    var c0 = cx + (relX - z * relY) * rx;
<a name="line351"></a>    var c1 = cy + (relY + z * relX) * ry;
<a name="line352"></a>    angle += inc;
<a name="line353"></a>    relX = Math.cos(angle);
<a name="line354"></a>    relY = Math.sin(angle);
<a name="line355"></a>    this.curveTo(c0, c1,
<a name="line356"></a>        cx + (relX + z * relY) * rx,
<a name="line357"></a>        cy + (relY - z * relX) * ry,
<a name="line358"></a>        cx + relX * rx,
<a name="line359"></a>        cy + relY * ry);
<a name="line360"></a>  }
<a name="line361"></a>  return this;
<a name="line362"></a>};
<a name="line363"></a>
<a name="line364"></a>
<a name="line365"></a>/**
<a name="line366"></a> * Iterates over the path calling the supplied callback once for each path
<a name="line367"></a> * segment. The arguments to the callback function are the segment type and
<a name="line368"></a> * an array of its arguments.
<a name="line369"></a> *
<a name="line370"></a> * The {@code LINETO} and {@code CURVETO} arrays can contain multiple
<a name="line371"></a> * segments of the same type. The number of segments is the length of the
<a name="line372"></a> * array divided by the segment length (2 for lines, 6 for  curves).
<a name="line373"></a> *
<a name="line374"></a> * As a convenience the {@code ARCTO} segment also includes the end point as the
<a name="line375"></a> * last two arguments: {@code rx, ry, fromAngle, extent, x, y}.
<a name="line376"></a> *
<a name="line377"></a> * @param {function(number, Array)} callback The function to call with each
<a name="line378"></a> *     path segment.
<a name="line379"></a> */
<a name="line380"></a>goog.graphics.Path.prototype.forEachSegment = function(callback) {
<a name="line381"></a>  var points = this.arguments_;
<a name="line382"></a>  var index = 0;
<a name="line383"></a>  for (var i = 0, length = this.segments_.length; i &lt; length; i++) {
<a name="line384"></a>    var seg = this.segments_[i];
<a name="line385"></a>    var n = goog.graphics.Path.segmentArgCounts_[seg] * this.count_[i];
<a name="line386"></a>    callback(seg, points.slice(index, index + n));
<a name="line387"></a>    index += n;
<a name="line388"></a>  }
<a name="line389"></a>};
<a name="line390"></a>
<a name="line391"></a>
<a name="line392"></a>/**
<a name="line393"></a> * Returns the coordinates most recently added to the end of the path.
<a name="line394"></a> *
<a name="line395"></a> * @return {Array.&lt;number&gt;?} An array containing the ending coordinates of the
<a name="line396"></a> *     path of the form {@code [x, y]}.
<a name="line397"></a> */
<a name="line398"></a>goog.graphics.Path.prototype.getCurrentPoint = function() {
<a name="line399"></a>  return this.currentPoint_ &amp;&amp; this.currentPoint_.concat();
<a name="line400"></a>};
<a name="line401"></a>
<a name="line402"></a>
<a name="line403"></a>/**
<a name="line404"></a> * @return {!goog.graphics.Path} A copy of this path.
<a name="line405"></a> */
<a name="line406"></a>goog.graphics.Path.prototype.clone = function() {
<a name="line407"></a>  var path = new this.constructor();
<a name="line408"></a>  path.segments_ = this.segments_.concat();
<a name="line409"></a>  path.count_ = this.count_.concat();
<a name="line410"></a>  path.arguments_ = this.arguments_.concat();
<a name="line411"></a>  path.closePoint_ = this.closePoint_ &amp;&amp; this.closePoint_.concat();
<a name="line412"></a>  path.currentPoint_ = this.currentPoint_ &amp;&amp; this.currentPoint_.concat();
<a name="line413"></a>  path.simple_ = this.simple_;
<a name="line414"></a>  return path;
<a name="line415"></a>};
<a name="line416"></a>
<a name="line417"></a>
<a name="line418"></a>/**
<a name="line419"></a> * Returns true if this path contains no arcs. Simplified paths can be
<a name="line420"></a> * created using {@code createSimplifiedPath}.
<a name="line421"></a> *
<a name="line422"></a> * @return {boolean} True if the path contains no arcs.
<a name="line423"></a> */
<a name="line424"></a>goog.graphics.Path.prototype.isSimple = function() {
<a name="line425"></a>  return this.simple_;
<a name="line426"></a>};
<a name="line427"></a>
<a name="line428"></a>
<a name="line429"></a>/**
<a name="line430"></a> * A map from segment type to the path function to call to simplify a path.
<a name="line431"></a> * @type {!Object}
<a name="line432"></a> * @private
<a name="line433"></a> */
<a name="line434"></a>goog.graphics.Path.simplifySegmentMap_ = (function() {
<a name="line435"></a>  var map = {};
<a name="line436"></a>  map[goog.graphics.Path.Segment.MOVETO] = goog.graphics.Path.prototype.moveTo;
<a name="line437"></a>  map[goog.graphics.Path.Segment.LINETO] = goog.graphics.Path.prototype.lineTo;
<a name="line438"></a>  map[goog.graphics.Path.Segment.CLOSE] = goog.graphics.Path.prototype.close;
<a name="line439"></a>  map[goog.graphics.Path.Segment.CURVETO] =
<a name="line440"></a>      goog.graphics.Path.prototype.curveTo;
<a name="line441"></a>  map[goog.graphics.Path.Segment.ARCTO] =
<a name="line442"></a>      goog.graphics.Path.prototype.arcToAsCurves;
<a name="line443"></a>  return map;
<a name="line444"></a>})();
<a name="line445"></a>
<a name="line446"></a>
<a name="line447"></a>/**
<a name="line448"></a> * Creates a copy of the given path, replacing {@code arcTo} with
<a name="line449"></a> * {@code arcToAsCurves}. The resulting path is simplified and can
<a name="line450"></a> * be transformed.
<a name="line451"></a> *
<a name="line452"></a> * @param {!goog.graphics.Path} src The path to simplify.
<a name="line453"></a> * @return {!goog.graphics.Path} A new simplified path.
<a name="line454"></a> */
<a name="line455"></a>goog.graphics.Path.createSimplifiedPath = function(src) {
<a name="line456"></a>  if (src.isSimple()) {
<a name="line457"></a>    return src.clone();
<a name="line458"></a>  }
<a name="line459"></a>  var path = new goog.graphics.Path();
<a name="line460"></a>  src.forEachSegment(function(segment, args) {
<a name="line461"></a>    goog.graphics.Path.simplifySegmentMap_[segment].apply(path, args);
<a name="line462"></a>  });
<a name="line463"></a>  return path;
<a name="line464"></a>};
<a name="line465"></a>
<a name="line466"></a>
<a name="line467"></a>// TODO(chrisn): Delete this method
<a name="line468"></a>/**
<a name="line469"></a> * Creates a transformed copy of this path. The path is simplified
<a name="line470"></a> * {@see #createSimplifiedPath} prior to transformation.
<a name="line471"></a> *
<a name="line472"></a> * @param {!goog.graphics.AffineTransform} tx The transformation to perform.
<a name="line473"></a> * @return {!goog.graphics.Path} A new, transformed path.
<a name="line474"></a> */
<a name="line475"></a>goog.graphics.Path.prototype.createTransformedPath = function(tx) {
<a name="line476"></a>  var path = goog.graphics.Path.createSimplifiedPath(this);
<a name="line477"></a>  path.transform(tx);
<a name="line478"></a>  return path;
<a name="line479"></a>};
<a name="line480"></a>
<a name="line481"></a>
<a name="line482"></a>/**
<a name="line483"></a> * Transforms the path. Only simple paths are transformable. Attempting
<a name="line484"></a> * to transform a non-simple path will throw an error.
<a name="line485"></a> *
<a name="line486"></a> * @param {!goog.graphics.AffineTransform} tx The transformation to perform.
<a name="line487"></a> * @return {!goog.graphics.Path} The path itself.
<a name="line488"></a> */
<a name="line489"></a>goog.graphics.Path.prototype.transform = function(tx) {
<a name="line490"></a>  if (!this.isSimple()) {
<a name="line491"></a>    throw Error(&#39;Non-simple path&#39;);
<a name="line492"></a>  }
<a name="line493"></a>  tx.transform(this.arguments_, 0, this.arguments_, 0,
<a name="line494"></a>      this.arguments_.length / 2);
<a name="line495"></a>  if (this.closePoint_) {
<a name="line496"></a>    tx.transform(this.closePoint_, 0, this.closePoint_, 0, 1);
<a name="line497"></a>  }
<a name="line498"></a>  if (this.currentPoint_ &amp;&amp; this.closePoint_ != this.currentPoint_) {
<a name="line499"></a>    tx.transform(this.currentPoint_, 0, this.currentPoint_, 0, 1);
<a name="line500"></a>  }
<a name="line501"></a>  return this;
<a name="line502"></a>};
<a name="line503"></a>
<a name="line504"></a>
<a name="line505"></a>/**
<a name="line506"></a> * @return {boolean} Whether the path is empty.
<a name="line507"></a> */
<a name="line508"></a>goog.graphics.Path.prototype.isEmpty = function() {
<a name="line509"></a>  return this.segments_.length == 0;
<a name="line510"></a>};
</pre>


</body>
</html>
